package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import com.atguigu.lease.web.admin.service.RoomPaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * projectName: com.atguigu.lease.web.admin.controller.apartment
 *
 * @author: wangs
 * description:
 */
@Tag(name = "支付方式管理")
@RestController
@RequestMapping("/admin/payment")
public class PaymentTypeController {

    @Autowired
    private PaymentTypeService paymentTypeService;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result findAll(){
        // 调用 PaymentTypeService中的list方法
        List<PaymentType> paymentTypeList = paymentTypeService.list();
//        return Result.build(paymentTypeList, ResultCodeEnum.SUCCESS);
        return Result.ok(paymentTypeList);
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType){
        // 调用paymentTypeService中保存或更新的方法
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deleteById(@RequestParam Long id){
        // 调用paymentTypeService中根据id删除的方法
        paymentTypeService.removeById(id);
        return Result.ok();
    }

}
